package com.animationsp.acs.interceptor;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import com.animationsp.acs.util.Constant;
import com.animationsp.acs.util.CookieManager;
import com.animationsp.acs.util.UserRoleUtil;
import com.opensymphony.webwork.ServletActionContext;
import com.opensymphony.xwork.Action;
import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.interceptor.Interceptor;

public class CheckAdminInterceptor implements Interceptor {

	public void destroy() {
		// TODO Auto-generated method stub

	}

	public void init() {
		// TODO Auto-generated method stub

	}

	public String intercept(ActionInvocation invocation) throws Exception {
		HttpServletRequest request=ServletActionContext.getRequest();
		Cookie userCookie = CookieManager.getCookie(request, Constant.COOKIE_NAME);
		String username = userCookie.getValue().split("/")[0];
		if(UserRoleUtil.isAdmin(username)){
			return invocation.invoke();
		}else{
			return Action.NONE;
		}
	}

}
